<html>
<head><meta charset="utf-8"><title>Rewriting HIR expressions · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rewriting.20HIR.20expressions.html">Rewriting HIR expressions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="163036082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rewriting%20HIR%20expressions/near/163036082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ange <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rewriting.20HIR.20expressions.html#163036082">(Apr 10 2019 at 19:12)</a>:</h4>
<p>are there any examples in rustc of code modifying the HIR representation? There's a <code>mut_visitor.rs</code> for the AST, but not sure where to look for HIR adjustments</p>



<a name="163165765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rewriting%20HIR%20expressions/near/163165765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rewriting.20HIR.20expressions.html#163165765">(Apr 12 2019 at 07:09)</a>:</h4>
<p>I’m no expert in this area, but if I don’t think there’s an equivalent to <code>mut_visitor.rs</code> for the HIR. <del>There might be a part of the compiler I’m forgetting and someone may correct me, but I don’t think the HIR is generally modified.</del> The HIR is read-only. </p>
<p>I think the closest you’ll get will be in the <a href="https://github.com/rust-lang/rust/blob/master/src/librustc/hir/lowering.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc/hir/lowering.rs">HIR lowering</a>. It’s not necessarily modifying the HIR, but it’s where the AST is transformed into the HIR and it’s where  things like <code>async fn</code> and <code>?</code> are desugared.</p>



<a name="163165828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rewriting%20HIR%20expressions/near/163165828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rewriting.20HIR.20expressions.html#163165828">(Apr 12 2019 at 07:10)</a>:</h4>
<p>HIR is read-only.</p>



<a name="163204505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rewriting%20HIR%20expressions/near/163204505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ange <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rewriting.20HIR.20expressions.html#163204505">(Apr 12 2019 at 16:18)</a>:</h4>
<p>thanks, it's good to know for sure :-) I see there's an adjustment table, though not sure if it's safe to use an adjustment to make some subexpressions unreferenced</p>



<a name="163204633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rewriting%20HIR%20expressions/near/163204633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ange <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rewriting.20HIR.20expressions.html#163204633">(Apr 12 2019 at 16:20)</a>:</h4>
<p>i.e. replace e.g. <code>foo.0.y</code> with <code>foo.0</code> -- this is in the context of RFC2229</p>



<a name="163204820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Rewriting%20HIR%20expressions/near/163204820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ange <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Rewriting.20HIR.20expressions.html#163204820">(Apr 12 2019 at 16:23)</a>:</h4>
<p>the type should stay the same, but no idea e.g. whether one needs to delete an unreferenced expr or not, etc.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>